package com.zhou.jiancai.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.zhou.jiancai.R;
import com.zhou.jiancai.activity.MainActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/3/10.
 */

class MyAtuoViewPagerAdapter extends PagerAdapter {


    private List<View> mAutoViewList;
    private  Context mContext;
    private  int[] images;
    private LayoutInflater mInflater;

    public MyAtuoViewPagerAdapter(List<View> mAutoViewList, Context context, int[] images) {
        this.mAutoViewList = mAutoViewList;


            this.mContext = context;
            this.images = images;
            mInflater = LayoutInflater.from(mContext);



    }

    @Override
    public int getCount() {
        return mAutoViewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View imageLayout = mInflater.inflate(R.layout.home_ads_view, container, false);
        ImageView imageView = (ImageView) imageLayout
                .findViewById(R.id.ads_view);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        final int index = position % images.length;
        imageView.setBackgroundResource(images[index]);

        container.addView(imageLayout, 0);


        container.addView(mAutoViewList.get(position));
        return  imageLayout;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
        container.removeView(mAutoViewList.get(position));
    }
}